package com.tj.shopping.web.controller;


import com.tj.shopping.service.IGoodInfoServiceImpl;
import com.tj.shopping.service.impl.GoodInfoServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/tj")
public class GoodInfoController extends BaseController{

    private IGoodInfoServiceImpl service=new GoodInfoServiceImpl();



    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String op=req.getParameter("op");
        if ("findGoods".equals(op)){
            dofinds(req,resp);
        }else if ("searchGoods".equals(op)){
            searchGoods(req, resp);
        }
    }


    protected void dofinds(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        Map<String,Object>map=parseRequest(req);

        Map<String,Object>map1=service.finds(map);
        printToJson(resp,map1);
    }
    protected void searchGoods(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        Map<String,Object>map=parseRequest(req);
        if (map.get("page")!=null&&map.get("limit")!=null){
            map.put("page",Integer.parseInt((String) map.get("page")));
            map.put("limit",Integer.parseInt((String) map.get("limit")));
        }
        if (map.get("gno")!=null){
            map.put("gno",Integer.parseInt((String) map.get("gno")));
        }
        Map<String,Object>map1=service.searchGoods(map);
        printToJson(resp,map1);
    }
}
